package demo2;

import java.util.Arrays;

public class Main {
    public static void main(String[] args) {
        int[] nums={0,1,2,2,3,0,4,2};
        Solution solution = new Solution();
        System.out.println(solution.removeElement(nums,2));
        System.out.println(Arrays.toString(nums));
    }
}

class Solution {
    public int removeElement(int[] nums, int val) {
        int num = nums.length;
        for (int i = 0; i < num; i++) {
            while(nums[i]==val && i<num-1){
                for (int j = i; j < num-1; j++) {
                    nums[j]=nums[j+1];
                }
                num--;
            }
            if (nums[i]==val&&i==num-1) {
                num--;
                break;
            }
        }
        return num;
    }
}
